package com.industrial.operation.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;

import cn.hutool.core.date.DateUtil;
import com.industrial.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationPower;
import com.industrial.operation.service.IOperationPowerService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 社会用电量Controller
 * 
 * @author ZHOU_S
 * @date 2024-01-19
 */
@RestController
@RequestMapping("/power")
public class OperationPowerController extends BaseController
{
    @Autowired
    private IOperationPowerService operationPowerService;

    /**
     * 查询社会用电量列表
     */
    @RequiresPermissions("operation:power:list")
    @GetMapping("/list")
    public TableDataInfo list(OperationPower operationPower)
    {
        String years=String.valueOf(DateUtil.year(new Date()));
        operationPower.setYears(years);
        startPage();
        List<OperationPower> list = operationPowerService.selectOperationPowerList(operationPower);
        return getDataTable(list);
    }

    /**
     * 导出社会用电量列表
     */
    @RequiresPermissions("operation:power:export")
    @Log(title = "社会用电量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationPower operationPower)
    {
        List<OperationPower> list = operationPowerService.selectOperationPowerList(operationPower);
        ExcelUtil<OperationPower> util = new ExcelUtil<OperationPower>(OperationPower.class);
        util.exportExcel(response, list, "社会用电量数据");
    }

    /**
     * 获取社会用电量详细信息
     */
    @RequiresPermissions("operation:power:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationPowerService.selectOperationPowerByBaseId(baseId));
    }

    /**
     * 新增社会用电量
     */
    @RequiresPermissions("operation:power:add")
    @Log(title = "社会用电量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationPower operationPower)
    {
        return toAjax(operationPowerService.insertOperationPower(operationPower));
    }

    /**
     * 修改社会用电量
     */
    @RequiresPermissions("operation:power:edit")
    @Log(title = "社会用电量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationPower operationPower)
    {
        return toAjax(operationPowerService.updateOperationPower(operationPower));
    }

    /**
     * 删除社会用电量
     */
    @RequiresPermissions("operation:power:remove")
    @Log(title = "社会用电量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationPowerService.deleteOperationPowerByBaseIds(baseIds));
    }
}
